package com.seal.commons.validator.jsr303;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;

public class PhoneNumValidator implements ConstraintValidator<PhoneNum, String> {

	@Override
	public void initialize(PhoneNum value) {
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext arg1) {
	    if(StringUtils.isBlank(value)){
            return true;
        }
		String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,5-9]))\\d{8}$";
		Pattern p = Pattern.compile(regex);
		Matcher m = p.matcher(value);
		return m.matches();
	}
}
